package sel.me.popular.library.learning.mapstruct;

import org.mapstruct.IterableMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.Date;
import java.util.List;

/**
 * @author shenenlu 2021年02月20日 下午14:12:47
 */
@Mapper(imports = PersonAgeEnum.class)
public abstract class PersonMapper {

    public static PersonMapper INSTANCE = Mappers.getMapper(PersonMapper.class);


    @Named(value = "default")
    @Mapping(target = "ageDesc", expression = "java(PersonAgeEnum.get(personDO.getAge()).getDesc())")
    public abstract Person convertDO2Model(PersonDO personDO);

    @IterableMapping(qualifiedByName = "default")
    @Mapping(target = "ageDesc", expression = "java(PersonAgeEnum.get(personDO.getAge()).getDesc())")
    public abstract List<Person> convertDO2ModelList(List<PersonDO> personDO);


    @Mapping(target = "ageDesc", expression = "java(PersonAgeEnum.get(personDO.getAge()).getDesc())")
    @Mapping(target = "createTime", expression="java(currTime)")
    public abstract Person convertDO2ModelWithDate(PersonDO personDO, Date currTime);

    @Mapping(target = "ageDesc", expression = "java(PersonAgeEnum.get(personDO.getAge()).getDesc())")
    @Mapping(target = "createTime", expression="java(null)")
    public abstract Person convertDO2ModelWithNull(PersonDO personDO);




}
